package cn.minhx.domain.strategy.model.entity;

import cn.minhx.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.Nullable;

import static cn.minhx.types.common.Constants.StrategyRuleModel.STRATEGY_RULE_WEIGHT;
import static com.google.common.collect.Sets.newHashSet;

/**
 * 策略实体
 *
 * @author min
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity {

    /**
     * 抽奖策略ID
     */
    private Long strategyId;
    /**
     * 抽奖策略描述
     */
    private String strategyDesc;
    /**
     * 抽奖规则模型 rule_weight,rule_blacklist
     */
    private String ruleModels;

    @Nullable
    public String[] ruleModelArr() {
        if (StringUtils.isBlank(ruleModels)) {
            return null;
        }
        return ruleModels.split(Constants.COMMA);
    }

    public String getRuleWeight() {
        String[] ruleModelArr = ruleModelArr();
        if (null == ruleModelArr) {
            return null;
        }

        if (newHashSet(ruleModelArr).contains(STRATEGY_RULE_WEIGHT)) {
            return STRATEGY_RULE_WEIGHT;
        }
        return null;
    }

}
